package com.demo.demoproject.domain;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result {
    private Integer code;
    private String msg;
    private Object data;

    @NotNull
    @Contract(" -> new")
    public static Result success(){
        return new Result(200, "SUCCEED", null);
    }
    @NotNull
    @Contract("_ -> new")
    public static Result success(Integer code) {
        return new Result(code, "SUCCEED", null);
    }
    @NotNull
    @Contract("_ -> new")
    public static Result success(String msg) {
        return new Result(200, msg, null);
    }
    @NotNull
    @Contract("_ -> new")
    public static Result success(Object data){
        return new Result(200, "SUCCEED", data);
    }
    @NotNull
    @Contract("_, _ -> new")
    public static Result success(Integer code, String msg) {
        return new Result(code, msg, null);
    }
    @NotNull
    @Contract("_, _ -> new")
    public static Result success(Integer code, Object data) {
        return new Result(code, "SUCCEED", data);
    }
    @NotNull
    @Contract("_, _, _ -> new")
    public static Result success(Integer code, String msg, Object data) {
        return new Result(code, msg, data);
    }

    @NotNull
    @Contract(" -> new")
    public static Result fail() {
        return new Result();
    }
    @NotNull
    @Contract("_ -> new")
    public static Result fail(Integer code) {
        return new Result(code, "FAILED", null);
    }
    @NotNull
    @Contract("_ -> new")
    public static Result fail(String msg) {
        return new Result(404, msg, null);
    }
    @NotNull
    @Contract("_, _ -> new")
    public static Result fail(Integer code, String msg) {
        return new Result(code, msg, null);
    }
    @NotNull
    @Contract("_, _, _ -> new")
    public static Result fail(Integer code, String msg, Object data) {
        return new Result(code, msg, data);
    }

    public Result notFound(){
        this.code = 404;
        this.msg = "NOT FOUND";
        return this;
    }
    public Result notLogin() {
        this.code = 401;
        this.msg = "NOT LOGIN";
        return this;
    }
    public Result unknownError(){
        this.code = 500;
        this.msg = "UNKNOWN ERROR";
        return this;
    }
}
